﻿using Manon.Admin.Web.Application;
using Manon.Admin.Web.Application.Dtos.Settings;
using Manon.Core;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Manon.Admin.Web.Controllers
{
    public class ChanelController : Controller
    {
        private readonly ISettingsService _settingsService;
        public ChanelController(ISettingsService settingsService)
        {
            _settingsService = settingsService;
        }

        public IActionResult Index()
        {
            return View();
        }

        public IActionResult Edit()
        {
            return View();
        }



        /// <summary>
        /// 获取栏目列表
        /// </summary>
        /// <returns></returns>
        [Authorize]
        [HttpGet]
        public async Task<List<GetChanelListTreeOutput>> GetChanelListTree()
        {
             
            var result = await _settingsService.GetChanelListTree();
            return result;
        }



        /// <summary>
        /// 获取栏目
        /// </summary>
        /// <returns></returns>
        [Authorize]
        [HttpGet]
        public async Task<GetChanelListTreeOutput> GetChanel(int Id)
        { 
            var result = await _settingsService.GetChanel(Id);
            return result;
        }


        /// <summary>
        /// 保存栏目
        /// </summary>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<Result> SaveChanel([FromBody] SaveChanelInput Input)
        { 
            var result = await _settingsService.SaveChanel(Input);
            return result;
        }


        /// <summary>
        /// 删除栏目
        /// </summary>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<Result> DeleteChanel(int Id)
        { 
            var result = await _settingsService.DeleteChanel(Id);
            return result;
        }

        /// <summary>
        /// 删除栏目
        /// </summary>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<Result> SetChanelEnabled(int Id, bool Enabled)
        { 
            var result = await _settingsService.SetChanelEnabled(Id, Enabled);
            return result;
        }
    }
}
